package quickSort;

import quickSortMediana3.QuickSortMedianThree;

public class QuickImplementation {

/*	void quicksort (int[] a, int l, int r) {
		if (l>=r) return;
		int m = partition(a, l, r);
		quicksort(a,l,m-1);
		quicksort(a,m+1,r);
		}*/
	
	public void quickSortMedian3(int[] array, int left, int right) {
		int index = particiona(array, left, right);
		if (left < index -1)
			quickSortMedian3(array, left, index-1);
		if (index < right)
			quickSortMedian3(array, index, right);
	}
	
	public int particiona(int[] array, int left, int right) {
		int l = left, r = right;
		int temp;
		int pivot = array[(left+right)/2];
		
		while (l <= r) {
			while (array[l] < pivot)
				l++;
			
			while (array[r] > pivot)
				r--;
			
			if (l  <= r) {
				temp = array[l];
				array[l] = array[r];
				array[r] = temp;
				l++;
				r--;
			}
		};
		return l;
	}

}
